package cn.zzuli.ex1;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
     List<Fragment> fragments;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fragments=new ArrayList<>();
        fragments.add(BlankFragment.newInstance(R.color.black,"one"));
        fragments.add(BlankFragment.newInstance(R.color.purple_700,"two"));
        fragments.add(BlankFragment.newInstance(R.color.white,"three"));
        fragments.add(BlankFragment.newInstance(R.color.teal_700,"four"));
        ViewPager viewpager=findViewById(R.id.vp);
        viewpager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @NonNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });


    }
}